#! /usr/bin/env python3
# coding: utf-8

import sys
from PyQt5.QtWidgets import QWidget, QPushButton, QApplication
from PyQt5.QtCore import QCoreApplication


class CloseDemo(QWidget):

    def __init__(self):
        super().__init__()

        self.initUI()

    def initUI(self):

        qbtn = QPushButton('exit', self)
        qbtn.clicked.connect(QCoreApplication.instance().quit)
        qbtn.resize(qbtn.sizeHint())
        qbtn.move(50, 50)

        self.setGeometry(300,300,300,300)
        self.setWindowTitle('Quit Demo')
        self.show()

if __name__ == '__main__':
    app = QApplication(sys.argv)
    ex = CloseDemo()
    sys.exit(app.exec_())